package com.employeemanagementsystem.controller;

import com.employeemanagementsystem.dao.FeedbackDao;
import com.employeemanagementsystem.model.Feedback;
import com.employeemanagementsystem.model.User;

import jakarta.servlet.http.HttpSession;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/employee_home")
public class EmployeeInfoServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");

        if (user != null) {
            FeedbackDao feedbackDao = new FeedbackDao();
            List<Feedback> feedbacks = feedbackDao.getFeedbacksByEmployeeId(user.getId());
            request.setAttribute("feedbacks", feedbacks);
            request.getRequestDispatcher("/WEB-INF/jsp/employee_home.jsp").forward(request, response);
        } else {
            response.sendRedirect("login.jsp?error=Please log in first.");
        }
    }
}

